﻿<?xml version="1.0" encoding="UTF-8" ?>
<sqlMap namespace="ParentChild1" xmlns="http://ibatis.apache.org/mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >

  <!--Type aliases allow you to use a shorter name for long fully qualified class names.-->
  <alias>
    <typeAlias alias="Parent" type="MyBatis.DataMapper.Sqlite.Test.Domain.Parent, MyBatis.DataMapper.Sqlite.Test" />
    <typeAlias alias="Child" type="MyBatis.DataMapper.Sqlite.Test.Domain.Child, MyBatis.DataMapper.Sqlite.Test" />
  </alias>

  <resultMaps>
    <resultMap id="ParentResult" class="Parent" groupBy="Id">
      <result property="Id" column="Parent_Id" />
      <result property="RowVersion" column="Parent_RowVersion" />
      <result property="Description" column="Parent_Description"/>
      <result property="Children" resultMapping="ParentChild1.ChildResult" />
    </resultMap>

    <resultMap id="ChildResult" class="Child">
      <result property="Id" column="Child_Id" />
      <result property="RowVersion" column="Child_RowVersion" />
      <result property="ParentId" column="Child_ParentId" />
      <result property="Description" column="Child_Description"/>
    </resultMap>
  </resultMaps>

  <statements>
    <select id="GetAllParentsNPlus1" resultMap="ParentResult">
      SELECT
      parent.id          parent_id,
      parent.rowversion  parent_rowversion,
      parent.description parent_description,
      child.id           child_id,
      child.rowversion   child_rowversion,
      child.parentid     child_parentid,
      child.description  child_description
      FROM   parent
      LEFT JOIN child
      ON parent.id = child.parentid
    </select>
  </statements>
</sqlMap>